﻿@model HouseEditGetViewModel
@{
    ViewBag.Title = "编辑房源";
}

<article class="page-container">
    <form class="form form-horizontal" id="form">
        <input type="hidden" name="Id" value="@Model.House.Id"/>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>区域：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("RegionId", (List<SelectListItem>)ViewBag.ListRegion, new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>小区：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("CommunityId", (List<SelectListItem>)ViewBag.ListCommunity, new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>户型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("RoomTypeId", new SelectList(Model.RoomTypes, "Id", "Name", Model.House.RoomTypeId), new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="Address" id="Address" datatype="*2-50" value="@Model.House.Address" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>月租金：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="MonthRent" datatype="n" id="MonthRent" style="width:100px;" value="@Model.House.MonthRent" /> 元
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("StatusId", new SelectList(Model.Statuses, "Id", "Name", Model.House.StatusId), new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>面积：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" datatype="n" id="Area" name="Area" style="width:150px;" value="@Model.House.Area" /> m<sup>2</sup>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>装修：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("DecorateStatusId", new SelectList(Model.DecorateStatuses, "Id", "Name", Model.House.DecorateStatusId), new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>层数：</label>
            <div class="formControls col-xs-8 col-sm-9">
                房子在第
                <input type="text" class="input-text" datatype="n" id="FloorIndex" name="FloorIndex" style="width:100px;" value="@Model.House.FloorIndex" />
                层，楼房共
                <input type="text" class="input-text" datatype="n" id="TotalFloorCount" name="TotalFloorCount" style="width:100px;" value="@Model.House.TotalFloorCount" />
                层
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>朝向：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" id="Direction" datatype="*1-10" name="Direction" value="@Model.House.Direction" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>可看房时间：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" id="LookableDateTime" name="LookableDateTime"  style="width:150px;" value='@(Model.House.LookableDateTime==null?"":((DateTime)Model.House.LookableDateTime).ToString("yyyy-MM-dd"))' />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>入住时间：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text Wdate" id="CheckInDateTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="CheckInDateTime" style="width:150px;" value='@(Model.House.CheckInDateTime==null?"":((DateTime)Model.House.CheckInDateTime).ToString("yyyy-MM-dd"))'/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>业主姓名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" datatype="*1-20" id="OwnerName" name="OwnerName" value="@Model.House.OwnerName" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>业主电话：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" datatype="m" id="OwnerPhoneNum" name="OwnerPhoneNum" value="@Model.House.OwnerPhoneNum"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">房屋类型</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("TypeId", new SelectList(Model.Types, "Id", "Name", Model.House.TypeId), new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">房源描述</label>
            <div class="formControls col-xs-8 col-sm-9">
                <!--<textarea id="description" name="description"></textarea>-->
                <script id="containerDesc" name="Description" type="text/plain">
                    @Html.Raw(Model.House.Description)
                </script>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">配套设施</label>
            <div class="formControls col-xs-8 col-sm-9">
                @foreach (var att in Model.Attachments)
                {
                    <label for="attachmentIds_@att.Id" class="col-xs-4">
                        <input type="checkbox" class="checkbox" id="attachmentIds_@att.Id" value="@att.Id" name="AttachmentIds" checked="@Model.House.AttachmentIds.Contains(att.Id)">@att.Name
                    </label>
                }
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-success radius" id="admin-house-save" name="admin-house-save"><i class="icon-ok"></i> 确定</button>
            </div>
        </div>
    </form>
</article>

@section FooterScript
{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/messages_zh.js"></script>
    <!-- 日期控件 -->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/My97DatePicker/4.8/WdatePicker.js"></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/ueditor/1.4.3/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/ueditor/1.4.3/ueditor.all.js"></script>
    <script type="text/javascript">
        //初始化编辑器
        var ueDesc = UE.getEditor('containerDesc');

        //加载小区数据
        function loadCommunities(regionId) {
            var $SelectCommunity = $("#CommunityId");
            $SelectCommunity.empty();
            //regionId 为空
            if (regionId == "") {
                return false;
            }
            //regionId 不是数字
            if (isNaN(regionId)) {
                return false;
            }
            //非法 regionId
            if (parseInt(regionId) <= 0) {
                return false;
            }
            $.post("/WebAdmin/House/LoadCommunities", { regionId: regionId }, function (res) {
                if (res.status == "ok") {
                    for (var index in res.data) {
                        $SelectCommunity.append("<option value='" + res.data[index].id + "'>" + res.data[index].name + "</option>");
                    }
                }
            });
        }
        $(function () {
            var $SelectRegion = $("#RegionId");
            //初始化小区数据
            loadCommunities($SelectRegion.val());
            //切换城市
            $SelectRegion.change(function () {
                loadCommunities($(this).val());
            });


            $("#form").validate({
                rules: {
                    //Name: {
                    //    required: true
                    //},
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'POST',
                        url: "/WebAdmin/House/Edit",
                        success: function (res) {
                            if (res.status == "ok") {
                                parent.layer.msg('修改成功!', { icon: 1, time: 1000 }, function () {
                                    parent.$('.btn-refresh').click();
                                    //parent.location.reload(); //刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            } else if (res.status == "redirect") {
                                location.href = res.data;
                            } else if (res.status == "error") {
                                layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                            } else {
                                layer.msg("修改失败", { icon: 2, time: 1000 });
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('网络出错!', { icon: 2, time: 1000 });
                        }
                    });
                }
            });
        });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
}


